Page({
  data: {
    favorites: [
      {
        id: 1,
        name: '校园新闻标题1',
        desc: '这里是新闻的简要描述内容...',
        time: '2023-05-15',
        cover: '/static/news-cover1.jpg'
      },
      {
        id: 2,
        name: '校园新闻标题2',
        desc: '这里是新闻的简要描述内容...',
        time: '2023-05-10',
        cover: '/static/news-cover2.jpg'
      }
    ]
  },

  onLoad() {
    // 这里可以添加从服务器获取收藏数据的逻辑
  },

  navigateToDetail(e) {
    const id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: `/pages/news/detail/detail?id=${id}`
    })
  },

  deleteItem(e) {
    const id = e.currentTarget.dataset.id
    wx.showModal({
      title: '确认删除',
      content: '确定要删除这条收藏吗？',
      success: (res) => {
        if (res.confirm) {
          this.setData({
            favorites: this.data.favorites.filter(item => item.id !== id)
          })
          wx.showToast({
            title: '删除成功',
            icon: 'success'
          })
        }
      }
    })
  }
})
